﻿<template>
    <div class="layout-main">
        <el-row style="margin-bottom:12px">
            <el-button size="small" v-on:click="add()" type="primary">添加</el-button>
        </el-row>
        <el-form ref="wxMsgReply" label-position="right" label-width="120px" :model="wxMsgReply" :rules="rules">
            <el-input size="small" type="hidden" :model="wxMsgReply.id" />
            <el-form-item label="回复key" prop="key">
                <el-input size="small" v-model="wxMsgReply.key" v-if="wxMsgReply.type==1" placeholder="回复key" readonly style="width: 240px" />
                <el-input size="small" v-model="wxMsgReply.key" v-else placeholder="回复key" style="width: 240px" />
            </el-form-item>
            <el-form-item label="回复内容" prop="content">
                <el-input size="small" type="textarea" :rows="10" v-model="wxMsgReply.content" placeholder="回复内容" style="width: 240px" />
                <br />
                <br />
                <el-button size="small" type="success" @click="genUrl('/home/index.html','首页')">首页</el-button>
                <el-button size="small" type="success" @click="genUrl('/home/coupon.html','优惠券')">优惠券</el-button>
                <el-button size="small" type="success" @click="genUrl('/home/card.html','会员卡')">会员卡</el-button>
                <el-button size="small" type="success" @click="genUrl('/home/active.html','活动激活码')">活动激活码</el-button>
                <el-button size="small" type="success" @click="genUrl('/home/share.html','代言人')">代言人</el-button>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
                <el-input size="small" v-model="wxMsgReply.remark" placeholder="备注" style="width: 240px" />
            </el-form-item>
        </el-form>
        <div>
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" :loading="modalLoading" @click="ok">确定</el-button>
        </div>
    </div>
</template>
<script>
import api from '@/api/api'

export default {
    name: 'WxMsgReply',
    data() {
        return {
            loading: false,
            modalLoading: false,
            baseUrl: api.root,
            others: {

            },
            wxMsgReply: {

            },
            rules: {
                remark: [
                    { required: true, message: '备注不能为空' }
                ],
                content: [
                    { required: true, message: '回复内容不能为空' }
                ],
                key: [
                    { required: true, message: '关键字不能为空' }
                ]
            },
            wxMsgReplyId: null
        };
    },
    mounted: function() {
        this.wxMsgReplyId = this.$route.params.wxMsgReplyId;
        this.getDetail();

    },
    methods: {
        cbtime: function(value) {
            this.others;
        },
        getDetail: function() {
            if (this.wxMsgReplyId == null || this.wxMsgReplyId == undefined || this.wxMsgReplyId == "") return;
            var me = this;
            me.showLoading();
            me.$http.post("/sys/wxmsgreply/show_" + me.wxMsgReplyId + ".action").then(response => {
                var body = response;
                if (body.status == 0) {
                    me.wxMsgReply = body.obj;

                }
                me.hideLoading();
            }, response => {
                me.hideLoading();
            });
        },
        ok: function() {
            var ok = false;
            this.$refs['wxMsgReply'].validate((valid) => {
                ok = valid;
                if (valid) {

                } else {
                    this.errorMessage('请认真填写数据');
                }
            })
            if (!ok) return;
            var me = this;

            me.modalLoading = true;
            me.$http.post("/sys/wxmsgreply/doSave.action", me.wxMsgReply).then(response => {
                var body = response;
                if (body.status == 0) {
                    me.successMessage("保存成功！");

                    me.$router.push({ name: 'WxMsgReplyList' });

                } else {
                    me.errorMessage("操作异常!" + body.info);
                }
                me.modalLoading = false;
            }, response => {
                me.modalLoading = false;
            });
        },
        cancel: function() {
            this.wxMsgReply = {};
            this.modalEdit = false;
        },
        genUrl: function(suppix, name) {
            this.wxMsgReply.content = this.wxMsgReply.content + "<a href='" + this.baseUrl + suppix + "'>" + name + "</a>";
        }
    }
}
</script>
<style scoped>
</style>